package com.smartHire.service.impl;

import com.smartHire.dao.ShopDao;
import com.smartHire.domain.Shop;
import com.smartHire.service.GoodsService;
import com.smartHire.domain.Goods;
import com.smartHire.dao.GoodsDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.jsp.tagext.TryCatchFinally;
import java.util.List;

@Service("goodsService")
public class GoodsServiceImpl implements GoodsService{
    @Resource(name = "goodsDao")
    private GoodsDao goodsDao;
    @Resource(name = "shopDao")
    private ShopDao shopDao;

    public void setGoodsDao (GoodsDao goodsDao) {this.goodsDao=goodsDao;}

    @Override
    public int addGoods(Goods goods ){

        try {
            int nums = goodsDao.inserGoods(goods);
            return nums;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int deleteGoods(Goods goods ){

        try {
            int nums = goodsDao.removeGoods(goods);
            return nums;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }
    @Override
    public List<Goods> queryGoods() {
        try {
            List<Goods> goods = goodsDao.selectGoods();
            return goods;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> queryGoodsBySort(Goods goods) {
        try {
            List<Goods> goodses = goodsDao.selectGoodsBySort(goods);
            return goodses;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> queryShopGoodsBySort(Goods goods, String shopName) {

        try {

            Shop shop = new Shop();
            shop.setShop_name(shopName);

            shop = shopDao.selectShopByName(shop);

            goods.setShop_id(shop.getShop_id());

            List<Goods> goodes = goodsDao.selectShopGoodsBySort(goods);

            return goodes;

        }catch (Exception e)
        {
            e.printStackTrace();
        }


        return null;
    }

    @Override
    public List<Goods> queryAllGoodsBySort(Goods goods) {
        try {
            List<Goods> goodses = goodsDao.selectAllGoodsBySort(goods);
            return goodses;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> queryShopAllGoodsBySort(Goods goods, String shopName) {

        try {

            Shop shop = new Shop();
            shop.setShop_name(shopName);

            shop = shopDao.selectShopByName(shop);

            goods.setShop_id(shop.getShop_id());

            List<Goods> goodes = goodsDao.selectShopAllGoodsBySort(goods);

            return goodes;

        }catch (Exception e)
        {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public List<Goods> queryGoodsByAudit(Goods goods) {
        try {
            List<Goods> goodses = goodsDao.selectGoodsByAudit(goods);
            return goodses;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> query5GoodsByShop(String shopName) {


        try {

            Shop shop = new Shop();
            shop.setShop_name(shopName);

            shop = shopDao.selectShopByName(shop);

            Goods goods = new Goods();
            goods.setShop_id(shop.getShop_id());

            List<Goods> goodes = goodsDao.select5GoodsByShop(goods);

            return goodes;

        }catch (Exception e)
        {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public List<Goods> queryGoodsByShop(Goods goods) {
        try {
            List<Goods> goodses = goodsDao.selectGoodsByShop(goods);
            return goodses;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> query22Goods() {
        try {
            List<Goods> goodses = goodsDao.select22Goods();
            return goodses;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Goods> SearchGoods(String name, String type) {
        try {

            Goods goods = new Goods();
            goods.setGood_name(name);

            List<Goods> goodes = null;
            if(type.equals("1"))
            {
                goodes = goodsDao.selectGoodsByPriceUp(goods);
            }else if(type.equals("0"))
            {
                goodes = goodsDao.selectGoodsByPriceDown(goods);
            }else if(type.equals("2"))
            {
                goodes = goodsDao.selectGoodsBySalesUp(goods);
            }else if(type.equals("3"))
            {
                goodes = goodsDao.selectGoodsBySalesDown(goods);
            }else if(type.equals("4"))
            {
                goodes = goodsDao.searchAllGoods(goods);
            }

            return goodes;


        }catch (Exception e)
        {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    public Goods queryGoodsByName(Goods goods) {
        try {
            Goods goods1= goodsDao.selectGoodsByName(goods);
            return goods1;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Goods queryGoodsByID(Goods goods) {
        try {
            Goods goods1= goodsDao.selectGoodsByID(goods);
            return goods1;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    public int updateGoodsById(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsById(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateGoodsAmount(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsAmount(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateGoodsName(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsName(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateGoodsPrice(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsPrice(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateGoodsPicture(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsPriture(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateGoodsInventory(Goods goods) {
        try {
            int nums = goodsDao.updateGoodsInventory(goods);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }
}
